package com.bw.sparksql1.job1
import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.{DataFrame, SparkSession}
/**
  *
  */
object Job3 {
    def main(args: Array[String]): Unit = {
      Logger.getLogger("org").setLevel(Level.ERROR)
      val spark = SparkSession
        .builder()
        .master("local")
        .appName("Spark SQL basic example")
        .getOrCreate()
      val df: DataFrame = spark.read.json("person.json")
      df.createGlobalTempView("people")
      // Global temporary view is tied to a system preserved database`global_temp` (全局临时视图绑定到系统保留的数据库' global_temp ')
      spark.sql("SELECT * FROM global_temp.people").show()
      // Global temporary view is cross-session （temporary view是在session中共享的）
      spark.newSession().sql("SELECT * FROM global_temp.people").show()
    }
}
